// pages/mall-flash-sale/index.js
import {
    getNavigationbar,
} from "../../api/index.js"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        isAhow:false,
        scrollViewHeight: 0,
        dateList: [],
        goodsList: [],
        obj:{},
        cuteverystarttime: 0,
    },
    /**
     * 获取秒杀活动列表回调函数
     */
    getHttpSeckill() {
        getNavigationbar({
            act: 'seckill_list',
        }).then(res => {
            if (res) {
                const cuteverystarttime = parseInt(res[this.data.active].cuteverystarttime)
                this.setData({
                    dateList: res,
                    cuteverystarttime: cuteverystarttime
                })
                this.getHttpGoodsList()
            }
        })
    },
    /**
     * 获取秒杀活动详情列表
     * @param {*} seckill_detail_list 
     */
    getHttpGoodsList() {
        getNavigationbar({
            act: 'seckill_detail_list',
            cuteverystarttime: this.data.cuteverystarttime
        }).then(res => {
            if (res) {
                if (this.data.dateList[this.data.active].has_begin == 1) {
                    res.forEach(item => item.has_begin = 1)
                }
                console.log(this.data.dateList[this.data.active])
                res.forEach(element => {
                    if(this.data.obj.shop_status == 0 ||this.data.obj.shop_status == 1 ) {
                        element.price = '***'
                        element.marketprice = '***'
                        element.property_price = '***'
                    } 
                });
                wx.nextTick(() => {
                console.log(res)

                    this.setData({
                        goodsList: res
                    })
                })
            }
        })
    },
    /**
     * 计算页面可滚动区域的动态高度
     */
    computeScrollViewHeight() {
        let that = this
        let query = wx.createSelectorQuery().in(this)
        query.select('.header').boundingClientRect()
        query.exec(res => {
            let headerHeight = res[0].height;
            let winHeight; // 窗口可使用高度
            wx.getSystemInfo({
                success: (res) => {
                    winHeight = res.windowHeight
                }
            })
            let scrollHeight = winHeight - headerHeight - 40; // 滚动区域高度
            that.setData({
                scrollViewHeight: scrollHeight,
            })
        })
    },

    /**
     * 秒杀时间选择回调函数方法
     * @param {*} e 
     */
    handleOptionColumn(e) {
        const {
            index
        } = e.currentTarget.dataset
        this.setData({
            active: index
        })
    },

    /**
     * 跳转商品详情页回调函数方法
     */
    handleGoodsDetail(e) {
        const {
            value
        } = e.currentTarget.dataset
        const params = {
            goodsId: value.id,
            detailType: '10',
            act: "seckill_detail"
        }
        wx.navigateTo({
            url: `/pages/goods_detail/index?data=${JSON.stringify(params)}`,
        })
    },
    /**
     * 商品秒杀操作回调函数方法
     * @param {*} e 
     */
    handleFlashSale(e) {
        const {
            index
        } = e.currentTarget.dataset
    },
    onShareAppMessage: function () {
        return {
            title: '限时秒杀',
            path: `/pages/mall_flash_sale/index`, // 分享的页面路径
            imageUrl: '', // 分享的图片链接
        }
    },
    onShareTimeline: function () {
        return {
            title: '限时秒杀',
            path: `/pages/mall_flash_sale/index`, // 分享的页面路径
            imageUrl: '', // 分享的图片链接
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
        });
        let res = wx.getStorageSync('USER')
      console.log('setStorageSync',res)
      this.data.obj = res
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.getHttpSeckill()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.computeScrollViewHeight()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },


})